import * as types from './mutations_types';

export default {
  show_loading: ({
    commit
  }) => {
    return new Promise((resolve, reject) => {
      commit(types.SHOW_LOADING);
      resolve()
    });
  },
  hide_loading: ({ commit }) => {
    return new Promise((resolve, reject) => {
      commit(types.HIDE_LOADING);
      resolve()
    })
  },
  get_signature: ({ commit, state }, VUE) => {
    if (Date.now() > (state.cachedSignature.expire - 10) * 1000) {
      return new Promise((resolve, reject) => {
        VUE.$$api_global_ossSign({
          succFn: res => {
            if (res && res.OSSAccessKeyId != null) {
              commit(types.GET_SIGNATURE, res)
              resolve()
            } else {
              console.error('getSignature error')
            }
          }
        })
      })
    }
  }
};
